var status = -1;
var selectionLog = [];
var rank;

function start() {
    action(1, 0, 0)
}

function action(g, e, d) {
    if (im.getServerName().equals("BMS单机") && im.getServerName().equals("BMS至尊体验服") && !im.getServerName().equals("BMS至尊")) {
        im.playerMessage(1, " 使用环境异常，请还原服务端配置。");
        im.dispose();
        return
    }
    if (status == 0 && g == 0) {
        im.dispose();
        return
    }(g == 1) ? status++ : status--;
    selectionLog[status] = d;
    var b = -1;
    if (status <= b++) {
        im.dispose()
    } else {
        if (status === b++) {
            im.askYesNo("要使用鬼怪烟花吗？\r\n\r\n#e第1名#n :#k #b #t4310275# 1000个 #r#e(0。2%)#n \r\n#k#e第2名#n :#k #b #n#t4310275# 500个 #r#e(0。8%)#n#k\r\n#e第3名#n :#k#b #n #t4310275# 100个 #r#e(9%)#n\r\n#k#e第4名#n :#k #b #t4310275# 50个 #r#e(30%)#n\r\n#k#e第5名#n :  #k#b#i2023879:# 满月神圣气息#k#r#e (60%)#n#k\r\n\r\n（从背包中最前面的烟花开始使用）", 2, 9062228)
        } else {
            if (status === b++) {
                var c = im.rand(1, 1000);
                rank = c <= 2 ? 1 : c <= 10 ? 2 : c <= 100 ? 3 : c <= 400 ? 4 : 5;
                im.curNodeEventEnd(true);
                im.eventSKill(0);
                im.setInGameDirectionMode(true, false, true);
                var h = im.getPlayer().getPosition();
                im.inGameDirectionEvent_PushScaleInfo(0, 0, 1800, 0, h.x, h.y - 100);
                im.gainItem(2630975, -1)
            } else {
                if (status === b++) {
                    im.inGameDirectionEvent_AskAnswerTime(1500)
                } else {
                    if (status === b++) {
                        im.inGameDirectionEvent_AskAnswerTime(1500);
                        var f = [4, 7, 13, 15, 16, 17, 19, 21];
                        im.emotion(f[im.rand(0, f.length - 1)], 2500);
                        switch (im.rand(1, 8)) {
                            case 1:
                                im.effect_NormalSpeechBalloon("来，发射吧！", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 2:
                                im.effect_NormalSpeechBalloon("这次感觉不错……", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 3:
                                im.effect_NormalSpeechBalloon("拜托，拜托。", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 4:
                                im.effect_NormalSpeechBalloon("我感受到满月的气息了！", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 5:
                                im.effect_NormalSpeechBalloon("啊，这个感觉是？", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 6:
                                im.effect_NormalSpeechBalloon("很好，来感觉了。", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 7:
                                im.effect_NormalSpeechBalloon("飞起来吧！", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break;
                            case 8:
                                im.effect_NormalSpeechBalloon("啊，这个感觉是？", 1, 0, 0, 1500, 1, 0, 0, 6, 4, 0, null, im.getPlayer().getId());
                                break
                        }
                    } else {
                        if (status === b++) {
                            im.fieldEffect_PlayFieldSound("Sound/SoundEff.img/Firework/start", 100);
                            im.inGameDirectionEvent_AskAnswerTime(2500);
                            im.effect_OnUserEff("Effect/CharacterEff.img/event_fireworks/0")
                        } else {
                            if (status === b++) {
                                im.fieldEffect_PlayFieldSound("Sound/SoundEff.img/Firework/five", 100);
                                im.inGameDirectionEvent_AskAnswerTime(1100);
                                im.effect_OnUserEff("Effect/CharacterEff.img/event_fireworks/" + (6 - rank))
                            } else {
                                if (status === b++) {
                                    im.addNumberForQuestInfo(500839, "total", 1);
                                    im.getTopMsgFont(rank + "名当选！", 3, 30, 4, 0, 0);
                                    im.inGameDirectionEvent_AskAnswerTime(1000);
                                    if (rank == 1) {
                                        im.gainItem(4310275, 1000)
                                    } else {
                                        if (rank == 2) {
                                            im.gainItem(4310275, 500)
                                        } else {
                                            if (rank == 3) {
                                                im.gainItem(4310275, 100)
                                            } else {
                                                if (rank == 4) {
                                                    im.gainItem(4310275, 50)
                                                } else {
                                                    im.gainSkillBuff(2023879)
                                                }
                                            }
                                        }
                                    }
                                    var a = im.addNumberForQuestInfo(500839, rank, 1);
                                    if (rank == 1) {
                                        im.getTopMsgFont("获得鬼怪铜币1000个！", 3, 20, 4, 0, 0);
                                        im.playerMessage(5, "鬼怪烟花当选第1名！惊喜地获得了鬼怪铜币1000个。")
                                    } else {
                                        if (rank == 2) {
                                            im.getTopMsgFont("获得鬼怪铜币500个！", 3, 20, 4, 0, 0);
                                            im.playerMessage(5, "鬼怪烟花当选第2名！开心地获得了鬼怪铜币500个。")
                                        } else {
                                            if (rank == 3) {
                                                im.getTopMsgFont("获得鬼怪铜币100个！", 3, 20, 4, 0, 0);
                                                im.playerMessage(5, "鬼怪烟花当选第3名！满足地获得了鬼怪铜币100个。")
                                            } else {
                                                if (rank == 4) {
                                                    im.getTopMsgFont("获得鬼怪铜币50个！", 3, 20, 4, 0, 0);
                                                    im.playerMessage(5, "鬼怪烟花当选第4名！小小地获得了鬼怪铜币50个。")
                                                } else {
                                                    im.getTopMsgFont("鬼怪烟花绽放，总共收到了" + a + "次满月神圣气息。", 3, 20, 4, 0, 0);
                                                    im.playerMessage(5, "鬼怪烟花绽放，总共收到了" + a + "次满月神圣气息。");
                                                    if (a >= 77 && im.getNumberFromAccountQuestInfo(221, "a", 0) == 0) {
                                                        im.setStringForAccountQuestInfo(221, "a", 1)
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if (status === b++) {
                                        im.OverlapScreenDetail19(0, 1000, 3000, 1);
                                        im.inGameDirectionEvent_PushScaleInfo(0, 0, 1000, 2147483647, 2147483647, 2147483647)
                                    } else {
                                        if (status === b++) {
                                            im.inGameDirectionEvent_PushMoveInfo(1, 0, 0, 0)
                                        } else {
                                            if (status === b++) {
                                                im.inGameDirectionEvent_AskAnswerTime(300)
                                            } else {
                                                if (status === b++) {
                                                    im.fieldEffect_RemoveOverlapScreenDetail(1000);
                                                    im.inGameDirectionEvent_ForcedFlip15(700, 0, 0, 0, 0);
                                                    im.eventSKill(0);
                                                    im.setInGameDirectionMode(false, true, false);
                                                    im.dispose()
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
};